package bean;

import java.util.Collection;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import javax.servlet.http.HttpSession;

import psc.model.base.acesso.Cliente;
import psc.model.base.acesso.Rotina;

@ManagedBean
@SessionScoped
public class MenuBean {

	private String rotina;

	public String getRotina() {
		return rotina;
	}

	public void setRotina(String rotina) {
		this.rotina = rotina;
	}

	public Boolean temPermissao() {
		
		FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) facesContext.getExternalContext()
				.getSession(false);

		Cliente cliente = (Cliente) session.getAttribute("usuario");
		Collection<Rotina> rotinas = cliente.getPerfil().getPermissoes();

		for (Rotina rotinaAux : rotinas) {
			if (rotinaAux.getNome().equals(rotina))
				return true;
		}
		return false;
	}
}
